<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Travian - a package for the web-based game Travian.</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>

<body style="background-color: white">

<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#constants">CONSTANTS</a></li>
	<ul>

		<li><a href="#attack_reinforcement">ATTACK_REINFORCEMENT</a></li>
		<li><a href="#attack_normal">ATTACK_NORMAL</a></li>
		<li><a href="#attack_raid">ATTACK_RAID</a></li>
		<li><a href="#scout_resources">SCOUT_RESOURCES</a></li>
		<li><a href="#scout_defences">SCOUT_DEFENCES</a></li>
	</ul>

	<li><a href="#methods">METHODS</a></li>
	<ul>

		<li><a href="#new__"><code>new()</code></a></li>
		<li><a href="#server__"><code>server()</code></a></li>
		<li><a href="#base_url__"><code>base_url()</code></a></li>
		<li><a href="#error_msg__"><code>error_msg()</code></a></li>
		<li><a href="#login__"><code>login()</code></a></li>
		<li><a href="#logged_in__"><code>logged_in()</code></a></li>
		<li><a href="#get_login_form__"><code>get_login_form()</code></a></li>
		<li><a href="#post_login_form__"><code>post_login_form()</code></a></li>
		<li><a href="#logout__"><code>logout()</code></a></li>
		<li><a href="#village__"><code>village()</code></a></li>
		<li><a href="#next_village__"><code>next_village()</code></a></li>
		<li><a href="#no_of_villages__"><code>no_of_villages()</code></a></li>
		<li><a href="#village_id2index__"><code>village_id2index()</code></a></li>
		<li><a href="#parse_villages__"><code>parse_villages()</code></a></li>
		<li><a href="#village_overview__"><code>village_overview()</code></a></li>
		<li><a href="#village_centre__"><code>village_centre()</code></a></li>
		<li><a href="#send_troops__"><code>send_troops()</code></a></li>
		<li><a href="#post_send_troops_form__"><code>post_send_troops_form()</code></a></li>
		<li><a href="#construction__"><code>construction()</code></a></li>
		<li><a href="#report__"><code>report()</code></a></li>
	</ul>

	<li><a href="#parse_functions">PARSE FUNCTIONS</a></li>
	<ul>

		<li><a href="#parse_login_form__"><code>parse_login_form()</code></a></li>
		<li><a href="#parse_login_error_msg__"><code>parse_login_error_msg()</code></a></li>
		<li><a href="#parse_send_troops_confirm_form__"><code>parse_send_troops_confirm_form()</code></a></li>
		<li><a href="#parse_send_troops_error_msg__"><code>parse_send_troops_error_msg()</code></a></li>
	</ul>

	<li><a href="#functions">FUNCTIONS</a></li>
	<ul>

		<li><a href="#calc_traveltime__"><code>calc_traveltime()</code></a></li>
	</ul>

	<li><a href="#author">AUTHOR</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
	<li><a href="#copyright_and_license">COPYRIGHT AND LICENSE</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h2><a name="name">NAME</a></h2>
<p>Travian - a package for the web-based game Travian.</p>
<p>
</p>
<hr />
<h2><a name="synopsis">SYNOPSIS</a></h2>
<pre>
  use Travian;
  my $travian = Travian-&gt;new(4, agent =&gt; 'Mozilla/5.0');</pre>
<pre>
  if (!$travian-&gt;login($user, $pass))
  {
    print $travian-&gt;error_msg();
  }
  $travian-&gt;logged_in();</pre>
<pre>
  print $travian-&gt;server();
  print $travian-&gt;base_url();</pre>
<pre>
  my $village = $travian-&gt;village($village_id);
  $village = $travian-&gt;next_village();
  $village = $travian-&gt;village_overview();
  $village = $travian-&gt;village_centre();
  $travian-&gt;no_of_villages();</pre>
<pre>
  $travian-&gt;send_troops($type, $x, $y, Travian::Troops::Gauls-&gt;new(10), $scout_type);</pre>
<pre>
  my $woodcutter = $travian-&gt;construction(1);</pre>
<pre>
  my $report = $travian-&gt;report(1234);</pre>
<pre>
  $travian-&gt;logout();</pre>
<p>
</p>
<hr />
<h2><a name="description">DESCRIPTION</a></h2>
<p>This package defines routines for the web-based game Travian.</p>
<p>
</p>
<hr />
<h2><a name="constants">CONSTANTS</a></h2>
<p>
</p>
<h3><a name="attack_reinforcement">ATTACK_REINFORCEMENT</a></h3>
<p>Constant for send troops. Send reinforcements.</p>
<p>
</p>
<h3><a name="attack_normal">ATTACK_NORMAL</a></h3>
<p>Constant for send troops. Send a normal attack.</p>
<p>
</p>
<h3><a name="attack_raid">ATTACK_RAID</a></h3>
<p>Constant for send troops. Send a raid attack.</p>
<p>
</p>
<h3><a name="scout_resources">SCOUT_RESOURCES</a></h3>
<p>Constant for send troops. Scout for resources and troops.</p>
<p>
</p>
<h3><a name="scout_defences">SCOUT_DEFENCES</a></h3>
<p>Constant for send troops. Scout for defences and troops.</p>
<p>
</p>
<hr />
<h2><a name="methods">METHODS</a></h2>
<p>
</p>
<h3><a name="new__"><code>new()</code></a></h3>
<pre>
  use Travian;</pre>
<pre>
  my $travian = Travian-&gt;new($server_no, $ua_args);</pre>
<p>Create a new instance of the Travian object.
If $server_no is not given a default of 3 is used.
The Travian package is sub-classed from LWP::UserAgent and so optional $ua_args
can be passed as second argument. See LWP::UserAgent for details.</p>
<p>
</p>
<h3><a name="server__"><code>server()</code></a></h3>
<pre>
  $travian-&gt;server();</pre>
<p>Returns the current Travian server number.</p>
<p>
</p>
<h3><a name="base_url__"><code>base_url()</code></a></h3>
<pre>
  $travian-&gt;base_url();</pre>
<p>Returns the base url of the current Travian server.</p>
<p>
</p>
<h3><a name="error_msg__"><code>error_msg()</code></a></h3>
<pre>
  $travian-&gt;error_msg();</pre>
<p>Returns the error message if any.</p>
<p>
</p>
<h3><a name="login__"><code>login()</code></a></h3>
<pre>
  $travian-&gt;login($user, $pass);</pre>
<p>Log into Travian with given user and pass.
Returns 1 on success.
Use $travian-&gt;<code>error_msg()</code> to retrieve error message on failure.</p>
<p>
</p>
<h3><a name="logged_in__"><code>logged_in()</code></a></h3>
<pre>
  $travian-&gt;logged_in();
  returns BOOLEAN</pre>
<p>
</p>
<h3><a name="get_login_form__"><code>get_login_form()</code></a></h3>
<pre>
  $travian-&gt;get_login_form();</pre>
<p>Retrieves the Travian login form.
Used by $travian-&gt;login().</p>
<p>
</p>
<h3><a name="post_login_form__"><code>post_login_form()</code></a></h3>
<pre>
  $travian-&gt;post_login_form($login_args);</pre>
<p>Posts the Travian login form.
Used by $travian-&gt;login().</p>
<p>
</p>
<h3><a name="logout__"><code>logout()</code></a></h3>
<pre>
  $travian-&gt;logout();</pre>
<p>Log out of Travian.</p>
<p>
</p>
<h3><a name="village__"><code>village()</code></a></h3>
<pre>
  $travian-&gt;village();
  $travian-&gt;village($village_id);</pre>
<p>Returns the Travian village.</p>
<p>
</p>
<h3><a name="next_village__"><code>next_village()</code></a></h3>
<pre>
  $travian-&gt;next_village();
  
Returns the next Travian village.</pre>
<p>
</p>
<h3><a name="no_of_villages__"><code>no_of_villages()</code></a></h3>
<pre>
  $travian-&gt;no_of_villages();</pre>
<p>Returns the number of villages.</p>
<p>
</p>
<h3><a name="village_id2index__"><code>village_id2index()</code></a></h3>
<pre>
  $travian-&gt;village_id2index($village_id);</pre>
<p>Given a village id returns the index in the village array.
Used by $travian-&gt;village().</p>
<p>
</p>
<h3><a name="parse_villages__"><code>parse_villages()</code></a></h3>
<pre>
  $travian-&gt;parse_villages($village_overview_html);</pre>
<p>Parses the list of villages from the given village overview html and
returns the current village.
Used by $travian-&gt;login().</p>
<p>
</p>
<h3><a name="village_overview__"><code>village_overview()</code></a></h3>
<pre>
  $travian-&gt;village_overview();</pre>
<p>Retrieve the village overview and return the current village.</p>
<p>
</p>
<h3><a name="village_centre__"><code>village_centre()</code></a></h3>
<pre>
  $travian-&gt;village_centre();</pre>
<p>Retrieve the village centre and return the current village.</p>
<p>
</p>
<h3><a name="send_troops__"><code>send_troops()</code></a></h3>
<pre>
  $travian-&gt;send_troops($attack_type, $x, $y, $troops, $scout_type);</pre>
<p>Send the given troops on an attack of type $attack_type to coordinates $x, $y.
The attack type is 2 for reinforcements, 3 for normal and 4 for raid.
The troops are of type Travian::Troops.
The scout type is 1 for resources and 2 for defences. Only used when a spy type
troop is sent. Defaults to resources.</p>
<p>
</p>
<h3><a name="post_send_troops_form__"><code>post_send_troops_form()</code></a></h3>
<pre>
  $travian-&gt;post_send_troops_form($type, $x, $y, $troops);</pre>
<p>Posts the Travian send troops form.
Used by $travian-&gt;send_troops().</p>
<p>
</p>
<h3><a name="construction__"><code>construction()</code></a></h3>
<pre>
  $travian-&gt;construction($gid);</pre>
<p>Return the construction costs and times for the given gid.
Returns a Travian::Building object.</p>
<p>
</p>
<h3><a name="report__"><code>report()</code></a></h3>
<pre>
  $travian-&gt;report($report_id);</pre>
<p>Return the report for the given report id.
Returns a Travian::Report object.</p>
<p>
</p>
<hr />
<h2><a name="parse_functions">PARSE FUNCTIONS</a></h2>
<p>
</p>
<h3><a name="parse_login_form__"><code>parse_login_form()</code></a></h3>
<pre>
  &amp;parse_login_form($login_form, $user, $pass);</pre>
<p>Parse the login form html and return an array ref of the form input values.</p>
<p>
</p>
<h3><a name="parse_login_error_msg__"><code>parse_login_error_msg()</code></a></h3>
<pre>
  &amp;parse_login_error_msg($login_html);</pre>
<p>Parse and return the error message in the login html page.</p>
<p>
</p>
<h3><a name="parse_send_troops_confirm_form__"><code>parse_send_troops_confirm_form()</code></a></h3>
<pre>
  &amp;parse_send_troops_confirm_form($send_troops_confirm_form, $scout_type);</pre>
<p>Parse the send troops confirm form html and return an array ref of the form input values.</p>
<p>
</p>
<h3><a name="parse_send_troops_error_msg__"><code>parse_send_troops_error_msg()</code></a></h3>
<pre>
  &amp;parse_send_troops_error_msg($send_troops_html);</pre>
<p>Parse and return the error message in the send troops html page.</p>
<p>
</p>
<hr />
<h2><a name="functions">FUNCTIONS</a></h2>
<p>
</p>
<h3><a name="calc_traveltime__"><code>calc_traveltime()</code></a></h3>
<pre>
  &amp;calc_traveltime($attacker_x, $attacker_y, $defender_x, $defender_y, $velocity);
  
Returns the travel time in seconds to go from coords $attacker_x, $attacker_y to coords
$defender_x, $defender_y at given velocity.</pre>
<p>
</p>
<hr />
<h2><a name="author">AUTHOR</a></h2>
<p>Adrian D. Elgar, &lt;<a href="mailto:ade@wasters.com">ade@wasters.com</a>&gt;
Martin Robertson, &lt;<a href="mailto:marley@wasters.com">marley@wasters.com</a>&gt;</p>
<p>
</p>
<hr />
<h2><a name="see_also">SEE ALSO</a></h2>
<p>LWP::UserAgent, Travian::Village, Travian::Resources, Travian::Construction, Travian::Report</p>
<p>
</p>
<hr />
<h2><a name="copyright_and_license">COPYRIGHT AND LICENSE</a></h2>
<p>Copyright (C) 2007 by Adrian Elgar, Martin Robertson</p>
<p>This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.</p>

</body>

</html>
